package likou;

import java.util.Arrays;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2021/12/20 20:36
 */
public class _475 {
    public static void main(String[] args) {
        _475 one = new _475();
        System.out.println(one.findRadius(new int[]{282475249,622650073,984943658,144108930,470211272,101027544,457850878,458777923},
                new int[]{823564440,115438165,784484492,74243042,114807987,137522503,441282327,16531729,823378840,143542612}));
    }
    public int findRadius(int[] houses, int[] heaters) {
        int max = 0;
        Arrays.sort(heaters);
        for(int h:houses){
            max = Math.max(max,find(h,heaters));
        }
        return max;
    }
    public int find(int house,int[] heaters){
        int left = 0,right = heaters.length-1;
        while(left<=right){
            int mid = left+((right-left)>>1);
            if(heaters[mid]<=house){
                left = mid + 1;
            }else{
                right = mid -1;
            }
        }
        return Math.min(left>0?Math.abs(house-heaters[left-1]):Integer.MAX_VALUE,left<heaters.length?Math.abs(house-heaters[left]):Integer.MAX_VALUE);
    }
}
